package com.yq.day29;

import java.util.concurrent.TimeUnit;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/06/29 11:05
 */
public class Demo04 {
    public static Object OBJECT = new Object();

    public static void main(String[] args) {
        new Thread(()->{
            synchronized (OBJECT){
                try {
                    System.out.println("start wait");
                    OBJECT.wait();
                    System.out.println("enf wait");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"t1").start();

        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        new Thread(()->{
            synchronized (OBJECT){
                System.out.println("start notify");
                OBJECT.notify();
                System.out.println("end notify");
            }
        //    退出同步代码块的时候才会释放锁
        },"t2").start();


    }
}
